# -*- coding: utf-8 -*-
#  @Time    : 2021/6/23 21:09
#  @Author  : Ben
#  @File    : zfshow.py
import jieba
from pyecharts.charts import WordCloud, Pie, Bar, HeatMap
from pyecharts import options as opts

f = open('comment_csv.csv', 'r', encoding="utf-8").read()
data_list = {}
f = jieba.cut(f)
for i in f:
    if len(i) > 1:
        previous_count = data_list.get(i, 0)
        data_list[i] = previous_count + 1
print(data_list)
print(data_list.keys())
print(data_list.values())
wordcloud = (
    WordCloud(opts.InitOpts(width="500px", height="500px", page_title="七里香"))
        .add(series_name="七里香", data_pair=[list(z) for z in zip(data_list.keys(), data_list.values())], shape="circle",
             word_gap=25,
             rotate_step=45, width="1000px", height="1000px")
        .set_global_opts(
        title_opts=opts.TitleOpts(title="七里香词云"))
        .render("wangyiyun_wordcloud.html")
)

pie = (
    Pie(opts.InitOpts(width="950px", height="950px", page_title="七里香"))
        .add("七里香", [list(z) for z in zip(data_list.keys(), data_list.values())])
        .set_global_opts(
        title_opts=opts.TitleOpts(title="七里香网易云热评饼图"))
        .render("wangyiyun_pie.html")
)
for z in data_list.values():
    # print(z)
    print(type(z))
bar = (
    Bar(opts.InitOpts(width="950px", height="950px", page_title="七里香"))
        .add_xaxis([z for z in data_list.keys()])
        .add_yaxis(series_name="七里香", y_axis=[z for z in data_list.values()], bar_width="40%")
        .set_global_opts(
        title_opts=opts.TitleOpts(title="七里香网易云热评柱状图"))
        .render("wangyiyun_bar.html")
)

